package com.ywq.app.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ywq.app.dao.ArtRoomDao;
import com.ywq.app.domain.ArtArtist;
import com.ywq.app.domain.ArtRoom;
import com.ywq.app.domain.ArtRoomArtist;
import com.ywq.app.domain.ArtRoomPic;
import com.ywq.app.domain.ArtRoomVideo;
import com.ywq.common.exception.AppBusinessException;

public class ArtRoomDaoImpl extends SqlSessionDaoSupport implements ArtRoomDao{
	
	private static final Logger logger = LoggerFactory.getLogger(ArtRoomDaoImpl.class);
	
	/**
	 * 艺术画总数
	 */
	@Override
	public int getArtRoomListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtRoomMapper.getArtRoomListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtRoomListCount user failure.", e);
			}
			throw new AppBusinessException("getArtRoomListCount user failure.", e);
		}
	}
	/**
	 * 展览馆列表
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtRoom> getArtRoomList(Map<String, Object> map)
			throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtRoomMapper.getArtRoomList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtRoomList list failure.", e);
			}
			throw new AppBusinessException("getArtRoomList list failure.", e);
		}
	}
	/**
	 * 新增展览馆
	 */
	@Override
	public void insertArtRoom(ArtRoom artRoom) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.insertArtRoom",
							artRoom);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtRoom user failure.", e);
			}
			throw new AppBusinessException("insertArtRoom user failure.", e);
		}
	}
	/**
	 * 更新展览馆
	 */
	@Override
	public void updateArtRoom(ArtRoom artRoom) throws AppBusinessException {
		try {
			getSqlSession()
					.update("com.ywq.app.persistence.ArtRoomMapper.updateArtRoom",
							artRoom);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("updateArtRoom user failure.", e);
			}
			throw new AppBusinessException("updateArtRoom user failure.", e);
		}
	}
	//当前展览
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtRoom> getNowRoomList(Map<String, Object> map)throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtRoomMapper.getNowRoomList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getNowRoomList list failure.", e);
			}
			throw new AppBusinessException("getNowRoomList list failure.", e);
		}
	}
	//历史展览
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtRoom> getOldRoomList(Map<String, Object> map)throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtRoomMapper.getOldRoomList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getOldRoomList list failure.", e);
			}
			throw new AppBusinessException("getOldRoomList list failure.", e);
		}
	}
	//历史展览个数
	@Override
	public int getOldRoomListCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtRoomMapper.getOldRoomListCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getOldRoomListCount user failure.", e);
			}
			throw new AppBusinessException("getOldRoomListCount user failure.", e);
		}
	}
	//单个展览馆
	@Override
	public ArtRoom getInRoomById(Map<String, Object> map)throws AppBusinessException {

		try {
			return (ArtRoom) getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtRoomMapper.getInRoomById",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getInRoomById list failure.", e);
			}
			throw new AppBusinessException("getInRoomById list failure.", e);
		}
	}
	//展览馆与画家关联表
	@Override
	public void insertArtRoomIst(ArtRoomArtist artRoomArtist) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.insertArtRoomIst",
							artRoomArtist);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtRoomIst user failure.", e);
			}
			throw new AppBusinessException("insertArtRoomIst user failure.", e);
		}
	}
	@Override
	public void deleteRoomArtist(String identifier) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.deleteRoomArtist",
							identifier);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtRoomIst user failure.", e);
			}
			throw new AppBusinessException("insertArtRoomIst user failure.", e);
		}
	}
	
	//得到画家 byRoomid
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtArtist> getArtArtistList(String roomId)throws AppBusinessException {

		try {
			return getSqlSession().selectList(
							"com.ywq.app.persistence.ArtRoomMapper.getArtRoomArtistListByRoomId",
							roomId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("ArtArtist list failure.", e);
			}
			throw new AppBusinessException("ArtArtist list failure.", e);
		}
	}
	//展览馆与图片
	@Override
	public void insertArtRoomPic(ArtRoomPic artRoomPic) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.insertArtRoomPic",
							artRoomPic);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtRoomPic user failure.", e);
			}
			throw new AppBusinessException("insertArtRoomPic user failure.", e);
		}
	}
	//展览馆内展品数
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtRoomPic> getArtRoomPicById(Map<String, Object> map)throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtRoomMapper.getArtRoomPicById",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtRoomPicById list failure.", e);
			}
			throw new AppBusinessException("getArtRoomPicById list failure.", e);
		}
	}
	//某展览馆作品总数
	@Override
	public int getArtRoomPicByIdCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtRoomMapper.getArtRoomPicByIdCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getOldRoomListCount user failure.", e);
			}
			throw new AppBusinessException("getOldRoomListCount user failure.", e);
		}
	}
	//删除
	@Override
	public void deleteRoomPic(Map<String, Object> map) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.deleteRoomPic",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtRoomPic user failure.", e);
			}
			throw new AppBusinessException("insertArtRoomPic user failure.", e);
		}
	}
	@Override
	public void deleteRoom(Map<String, Object> map) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.deleteRoom",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteRoom user failure.", e);
			}
			throw new AppBusinessException("deleteRoom user failure.", e);
		}
	}
	//视频
	@Override
	public void insertArtFlv(ArtRoomVideo artRoomVideo) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.insertArtFlv",
							artRoomVideo);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("insertArtFlv user failure.", e);
			}
			throw new AppBusinessException("insertArtFlv user failure.", e);
		}
	}
	//视频总数
	@Override
	public int getArtRoomFlvCount(Map<String, Object> map)throws AppBusinessException {
		try {
			Object obj = getSqlSession()
					.selectOne(
							"com.ywq.app.persistence.ArtRoomMapper.getArtRoomFlvCount",
							map);
			return (Integer) (obj == null ? 0 : obj);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtRoomFlvCount user failure.", e);
			}
			throw new AppBusinessException("getArtRoomFlvCount user failure.", e);
		}
	}
	//视频
	@SuppressWarnings("unchecked")
	@Override
	public List<ArtRoomVideo> getArtRoomFlv(Map<String, Object> map)throws AppBusinessException {

		try {
			return getSqlSession()
					.selectList(
							"com.ywq.app.persistence.ArtRoomMapper.getArtRoomFlv",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getArtRoomFlv list failure.", e);
			}
			throw new AppBusinessException("getArtRoomFlv list failure.", e);
		}
	}
	//
	@Override
	public void deleteFlv(Map<String, Object> map) throws AppBusinessException {
		try {
			getSqlSession()
					.insert("com.ywq.app.persistence.ArtRoomMapper.deleteFlv",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("deleteFlv user failure.", e);
			}
			throw new AppBusinessException("deleteFlv user failure.", e);
		}
	}
}
